package com.ruoyi.app.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.message.domain.MessageInfo;
import com.ruoyi.message.domain.MessageRead;
import com.ruoyi.message.domain.MessageZan;
import com.ruoyi.message.service.IMessageInfoService;
import com.ruoyi.message.service.IMessageReadService;
import com.ruoyi.message.service.IMessageZanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 动态Controller
 * 
 * @author hct
 * @date 2022-04-14
 */
@RestController
@RequestMapping("/app/public/message")
public class AppMessageInfoController extends BaseController
{
    @Autowired
    private IMessageInfoService messageInfoService;
    @Autowired
    private IMessageReadService messageReadService;

    /**
     * 查询动态列表
     */
    @GetMapping("/index")
    public TableDataInfo index(MessageInfo messageInfo)
    {
        startPage();
        List<MessageInfo> list = messageInfoService.selectMessageInfoList(messageInfo);
        return getDataTable(list);
    }


    /**
     * 获取动态详细信息
     */
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {   MessageInfo messageInfo=messageInfoService.selectMessageInfoById(id);
        MessageRead messageRead=new MessageRead();
        //登陆用户
        messageRead.setMemberId(messageInfo.getMemberId());
        messageRead.setMessageId(messageInfo.getId());
        messageRead.setCreateDate(new Date());
        messageReadService.insertMessageRead(messageRead);
        messageInfo.setReadnum(messageInfo.getReadnum()+1);
        messageInfoService.updateMessageInfo(messageInfo);
        return AjaxResult.success(messageInfo);
    }



}
